home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 …ember: Reference Library / Dev.CD Dec 98 RL2.toast / Technical Publications / macosx / Carbon Dater / _Engine Room / lib / Mac / Apps / PBar.pm < prev   
Encoding:
Text File  |  1998-03-21  |  7.1 KB  |  289 lines  |  [TEXT/McPL]

  1. #!perl -w
  2. package Mac::Apps::PBar;
  3. require 5.00201;
  4. use vars qw($VERSION @ISA @EXPORT $be $evt);
  5. use strict;
  6. no strict 'refs';
  7. use Exporter;
  8. use Carp;
  9. use Mac::AppleEvents;
  10. use Mac::Apps::Launch;
  11. @ISA = qw(Exporter);
  12. @EXPORT = ();
  13. $VERSION = sprintf("%d.%02d", q$Revision: 1.30 $ =~ /(\d+)\.(\d+)/);
  14. $be = '';
  15.  
  16.  
  17. sub new {
  18.      my $pkg = shift;
  19.      my $title = shift;
  20.      my $ppos = shift;
  21.      $pkg = \*$pkg;
  22.      bless $pkg;
  23.  
  24.      ${*$pkg}{'windobj'} = "obj{want:type(cwin),
  25.      from:null(), form:indx, seld:long(1)}";
  26.  
  27.      ${*$pkg}{'progobj'} = "obj{want:type(PBar),
  28.      from:${*$pkg}{'windobj'}, form:indx, seld:long(1)}";
  29.      
  30.      $pkg->launch_pbar;
  31.  
  32.      $evt = AEBuildAppleEvent('core', 'crel', typeApplSignature, 'PBar', 0, 0,
  33.      "kocl: type(cwin), prdt:{ pnam: “$title” , ppos:[$ppos] }") or die $^E;
  34.      $pkg->runEvent($evt);
  35.  
  36.      $pkg;
  37. }
  38.  
  39. sub launch_pbar {
  40.     LaunchApps(['PBar'],1);
  41. }
  42.  
  43. sub data {
  44.     my $pkg = shift;
  45.     my $str = shift;
  46.     my $dat = shift;
  47.     if (!$dat && keys %$str) {
  48.         my $s;
  49.         foreach $s (keys %$str) {
  50.             $pkg->_procData($s,$$str{$s});
  51.         }
  52.     } elsif ($str && $dat) {
  53.         $pkg->_procData($str,$dat);
  54.     }        
  55. }
  56.  
  57. sub _procData {
  58.     my $pkg = shift;
  59.     my $str = shift;
  60.     my $dat = shift;
  61.     my $obj = "obj{want:type(prop), from:${*$pkg}{'progobj'},
  62.     form:prop, seld:type($str)}";
  63.     my $evt = AEBuildAppleEvent('core', 'setd', typeApplSignature,
  64.     'PBar', 0, 0, "'----':$obj, data:“$dat” ") or die $^E;
  65.     $pkg->runEvent($evt)
  66. }
  67.  
  68. sub close_window {
  69.     my $pkg = shift;
  70.     my $evt = AEBuildAppleEvent('aevt', 'quit', typeApplSignature,
  71.   'PBar', 0, 0, "'----':''") or die $^E;
  72.     $pkg->runEvent($evt);
  73. }
  74.  
  75. sub runEvent {
  76.      my $pkg = shift;
  77.      my $evt = shift;
  78.     #print AEPrint($evt), "\n";
  79.      my $rep = AESend($evt, kAEWaitReply) or die $^E;
  80.     #print AEPrint($rep), "\n\n";
  81.      AEDisposeDesc $evt;
  82.      AEDisposeDesc $rep;
  83.  
  84. }
  85.  
  86.  
  87. 1;
  88.  
  89. __END__
  90.  
  91. =head1 NAME
  92.  
  93. Mac::Apps::PBar - An AppleEvent Module for Progress Bar 1.0.1
  94.  
  95. =head1 SYNOPSIS
  96.  
  97.     use Mac::Apps::PBar;
  98.     $bar = Mac::Apps::PBar->new('FTP DOWNLOAD', '100, 50');
  99.     $bar->data({
  100.         Cap1=>'file: BigFile.tar.gz',
  101.         Cap2=>'size: 1,230K',
  102.         MinV=>'0',
  103.         MaxV=>'1230',
  104.     });
  105.     for(0..10) {
  106.         $n = $_*123;
  107.         $bar->data(Valu, $n);
  108.         sleep(1);
  109.     }
  110.     sleep(5);
  111.     $bar->close_window;
  112.  
  113. =head1 DESCRIPTION
  114.  
  115. Progress Bar is a small AppleScriptable utility written by Gregory H. Dow. This
  116. module, C<PBar.pm>, generates Apple Event calls using AEBuild in place of AppleScript.
  117. Because the Apple Event Manager is not involved, Progress Bar updates more quickly.
  118.  
  119. In most applications the time taken to up date the Progress Bar must be kept to
  120. a minimum. On this machine (68030 CPU) An C<AppleScript> update to the progress bar
  121. takes about 0.72 seconds. Using C<PBar.pm> the time is reduced to 0.10 seconds;
  122. a seven-fold improvement.
  123.  
  124. Progress Bar 1.0.1 is found by a search for the creator type C<PBar> and launched
  125. automatically. To minimise the time taken for the search, C<Progress Bar 1.0.1> should
  126. be kept in the same volume as C<PBar.pm>. 
  127.  
  128. =head2 CREATING A NEW PROGRESS BAR
  129.  
  130. Progress Bar 1.0.1 is launced and a new Progress bar created by:
  131.  
  132.      $bar = Mac::Apps::PBar->new('NAME', 'xpos, ypos');
  133.  
  134. where the arguments to the C<new> constructor have the following meanings:
  135.  
  136. =over 4
  137.  
  138. =item First argument
  139.  
  140. is a string for the title bar of the Progress Bar window.
  141.  
  142. =item Second argument
  143.  
  144. is a string C<'xpos, ypos'> defining the position of the top left-hand corner 
  145. of the window in pixels. The pair of numbers and the comma should be enclosed
  146. in single quotes as shown.
  147.  
  148. =back
  149.  
  150. =head2 SENDING DATA
  151.  
  152. Values are sent to the C<Progress Bar> by the C<data> sub-routine using the
  153. variable names in the C<aete resource> for each of the C<Progress Bar> properties.
  154. There are five property values for the C<PBar> class. The syntax is:
  155.  
  156.     $bar->data('property', 'value')
  157.  
  158. or
  159.  
  160.     $bar->data({'property', 'value', 'property', 'value'})
  161.  
  162. The second method is suggested.
  163.  
  164. =over 4
  165.  
  166. =item B<Minimum value>  C<'MinV'>
  167.  
  168. This is the value of the displayed parameter corresponding to the origin of the
  169. bar. Often it is zero, but may take other values (for instance a temperature bar
  170. in degrees Fahrenheit might start at 32).
  171.  
  172. =item B<Maximum value>  C<'MaxV'>
  173.  
  174. This is the value corresponding to the full extent of the bar. It can take any
  175. value, such as the size of a file in KB, or 100 for a percentage variable. Bar
  176. increments are integers, hence discrimination is finer the larger the value of
  177. C<MaxV>.
  178.  
  179. =item B<Current value>  C<'Valu'>
  180.  
  181. This is the value which sets the progress bar to the position corresponding to
  182. the current value of the parameter displayed. The value must obviously lie
  183. somewhere between C<MinV> and C<MaxV>.
  184.  
  185. =item B<Upper caption>  C<'Cap1'>
  186.  
  187. This string, immediately under the title bar, can be set to anything appropriate
  188. for the application.
  189.  
  190. =item B<Lower caption>  C<'Cap2'>
  191.  
  192. The lower caption string can either be set to a constant value (e.g. C<File size = 1234K>)
  193. or up-dated with the bar. For instance it might be appropriate to set C<'Cap2'>
  194. as follows:
  195.  
  196.     $n = $max_value - $current_value;
  197.     $bar->data({Cap2=>"remaining $n"});
  198.  
  199. Note the double quotes so that the value of C<$n> is interpolated.
  200.  
  201. It should be remembered however that it will take twice as long to update both
  202. C<Cap2> and C<Valu> as just to update the bar C<Valu> by itself. In applications
  203. where speed is of the essence, just the bar value C<Valu> should be changed.
  204.  
  205. =back
  206.  
  207. =head2 SEE ALSO
  208.  
  209. The following documents, which are relevant to AEBuild, may be of interest:
  210.  
  211. =over 4
  212.  
  213. =item AEGizmos_1.4.1
  214.  
  215. Written by Jens Peter Alfke this gives a description of AEBuild on which the
  216. MacPerl AEBuildAppleEvent is based. Available from:
  217.  
  218.     ftp://dev.apple.com/
  219.     devworld/Tool_Chest/Interapplication_Communication/
  220.     AE_Tools_/AEGizmos_1.4.1
  221.  
  222. =item aete.convert
  223.  
  224. A fascinating MacPerl script by David C. Schooley which extracts the aete
  225. resources from scriptable applications. It is an invaluable aid for the
  226. construction ofAEBuild events. Available from:
  227.  
  228.     ftp://ftp.ee.gatech.edu/
  229.     pub/mac/Widgets/
  230.     aete.converter_1.1.sea.hqx
  231.  
  232. =item AE_Tracker
  233.  
  234. This a small control panel which allows some or all AE Events to be tracked at
  235. various selectable levels of information. It is relatively difficult to decipher
  236. the output but AE_Tracker can be helpful. Available from:
  237.  
  238.     ftp://ftp.amug.org/
  239.     pub/amug/bbs-in-a-box/files/system7/a/
  240.     aetracker2.0.sit.hqx
  241.  
  242. =item Inside Macintosh
  243.  
  244. Chapter 6 "Resolving and Creating Object Specifier Records" . The summary can
  245. be obtained from:
  246.  
  247.     http://gemma.apple.com/
  248.     dev/techsupport/insidemac/IAC/
  249.     IAC-287.html
  250.  
  251. =item Progress Bar 1.0.1
  252.  
  253. Obtainable from Info-Mac archives as:
  254.  
  255.     info-mac/dev/osa/progress-bar-1.0.1.hqx
  256.  
  257. =back
  258.  
  259. References are valid as of May 1997.
  260.  
  261. =head1 AUTHORS
  262.  
  263. Chris Nandor F<E<lt>pudge@pobox.comE<gt>>
  264. http://pudge.net/
  265.  
  266. Alan Fry F<E<lt>ajf@afco.demon.co.ukE<gt>>
  267.  
  268. Copyright (c) 1998 Chris Nandor and Alan Fry.  All rights reserved.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.  Please see the Perl Artistic License.
  269.  
  270. =head1 HISTORY
  271.  
  272. =over 4
  273.  
  274. =item Version 1.3, 3 January 1998
  275.  
  276. General cleanup.  Now requires MacPerl 5.1.4r4.
  277.  
  278. =item Version 1.2, 13 October 1997
  279.  
  280. Switched to Mac::Apps::Launch package.
  281.  
  282. =item Version 1.1, 16 September 1997
  283.  
  284. Put in the hashref methods to change multiple data in one call.
  285.  
  286. =back
  287.  
  288. =cut
  289.